home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
036a
/
pmfinder.zip
/
LZH.C
< prev
next >
Wrap
Text File
|
1991-12-05
|
3KB
|
92 lines
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h> /* needed for open, close, read, write, */
/* filelength, and eof */
#include <fcntl.h> /* needed for open mode arguments */
#include <sys\types.h> /* needed for file types */
#include <sys\stat.h> /* needed for status flags */
#include <malloc.h> /* needed for _memmax, malloc. and free */
#include "archive.h"
#include "lzh.h"
extern BOOL pascal fContinue;
/*
This module performs the LZH file search.
These functions have changed slightly from
Don A. Williams orginal code.
I've removed references to global variables.
*
*/
/***********************************************************************
* DoLzh is the main routine to process an entire LZH file *
***********************************************************************/
void
DoLzh (char *Pattern,char *Path,HWND hwndListBox)
{
FILE *LzhFile;
LZH_HEADER LzhHead;
char szListBox[260];
char *p;
char V_Name[14], V_Path[65];
char *Name;
if ( (LzhFile = fopen(Path, "rb")) == NULL )
{
strcpy(szListBox,
"LzhFile Error - Unable to open - ");
strcat(szListBox,Path);
AddToListBox(hwndListBox,szListBox);
}
else
{
while ( (Name = GetEntry(LzhFile, &LzhHead)) != NULL && fContinue )
{
if ( (p = strrchr(Name, '\\')) != NULL) ++p;
else p = Name;
if ( Match(p,Pattern) )
{
strcpy(V_Name, p);
strcpy(V_Path, Path);
sprintf(szListBox,"%s--> (%s)", V_Path, V_Name);
AddToListBox(hwndListBox,szListBox);
}
free(Name);
}
fclose(LzhFile);
}
}
/***********************************************************************
* GetEntry reads and verifys the next entry in the distributed *
* directory of an LZH file. *
***********************************************************************/
char *
GetEntry (FILE *LzhFile, LZH_HEADER *LzhDir) {
size_t Len;
char *Name;
if ( (Len = fread(LzhDir, 1, sizeof(LZH_HEADER), LzhFile)) < 2) {
if ( (Len != 1) || (LzhDir->HeadSize != 0X00) ) {
/*Couldn't read header*/
return(NULL);
}
return(NULL);
}
if ( (Name = malloc(LzhDir->FileNameLength + 1)) == NULL) {
/*Insufficient memory for file name */
return(NULL);
}
fread(Name, 1, LzhDir->FileNameLength, LzhFile);
Name[LzhDir->FileNameLength] = '\0';
fseek(LzhFile, sizeof(unsigned) + LzhDir->CompressedSize, SEEK_CUR);
return(Name);
}